const mysql = require('mysql');
const { configFile:{mysql: {test}}} = require('../config/readYamlFile');

const pool = mysql.createPool({
    ...test
});

function  query(sql, values, callback) {
    pool.getConnection(function (err, connection) {
        if(err) throw err;
        connection.query(sql, values = [],function (err, results, fields) {
            //每次查询都会 回调
            callback(err, results);
            //只是释放链接，在缓冲池了，没有被销毁
            connection.release();
            if(err) throw error;
        });
    });
}

exports.query = query;